home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!seismo!rutgers!ucla-cs!zen!ucbvax!decvax!tektronix!tekgen!tekred!games-request
- From: games-request@tekred.TEK.COM
- Newsgroups: comp.sources.games
- Subject: v02i033: pig - simple pig-latin translator
- Message-ID: <1546@tekred.TEK.COM>
- Date: 29 Aug 87 00:05:27 GMT
- Sender: billr@tekred.TEK.COM
- Lines: 92
- Approved: billr@tekred.TEK.COM
-
- Submitted by: root <ihnp4!killer!ozdaltx!root>
- Comp.sources.games: Volume 2, Issue 33
- Archive-name: pig
-
- [Here's a simple pig-latin translator in lex. I added
- the Makefile and fixed a bug. It's my recollection that
- pig-latin is actual a little more complex than this, but
- hey, I don't write 'em - I just post 'em. -br]
- [P.S. How about some more games? My queue is empty.]
-
- [[This is a lex file for a pig-latin translator. If you don't
- know what pig-latin is or are too young to remember... It
- was a "language" popular in the 40-50's. The rules are
- simple, move the first letter of each word to the end of the
- word and add an 'a'. For example; "pig-latin" becomes
- "igpa-atinla". I wrote this as an exercise trying to learn
- lex. It needs some cleaning up, but it works as is. Words
- that are all capitals are not parsed correctly, yet. Anyway,
- enjoy.
-
- ************************************************
- * Scotty * Adapt *
- * ihnp4!killer!ozdaltx!sysop * Enjoy *
- * "Ad Venerem Securiorem" * Survive *]]
- ----------------------
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: Makefile pig.l
- # Wrapped by billr@tekred on Fri Aug 28 16:56:20 1987
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f Makefile -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"Makefile\"
- else
- echo shar: Extracting \"Makefile\" \(102 characters\)
- sed "s/^X//" >Makefile <<'END_OF_Makefile'
- X# Makefile for pig - Pig-Latin translator
- X
- Xpig: pig.l
- X lex pig.l
- X cc -o pig lex.yy.c -ll
- X rm lex.yy.c
- END_OF_Makefile
- if test 102 -ne `wc -c <Makefile`; then
- echo shar: \"Makefile\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f pig.l -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"pig.l\"
- else
- echo shar: Extracting \"pig.l\" \(331 characters\)
- sed "s/^X//" >pig.l <<'END_OF_pig.l'
- X/* PIG - a pig-latin translator */
- X
- X%{
- X#include <ctype.h>
- Xchar *c, start;
- X%}
- X%%
- X[A-Za-z]+ {
- X if(yyleng >=2){
- X c=yytext;
- X if(isupper(yytext[0]))
- X start = tolower(yytext[0]);
- X else
- X start = yytext[0];
- X c++;
- X if(isupper(yytext[0]))
- X *c=toupper(*c);
- X printf("%s%ca",c,start);
- X } else {
- X ECHO;
- X }
- X}
- X%%
- Xmain()
- X{
- X yylex();
- X}
- END_OF_pig.l
- if test 331 -ne `wc -c <pig.l`; then
- echo shar: \"pig.l\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- echo shar: End of shell archive.
- exit 0
-